import React from 'react';
import { message as antdMessage } from 'antd';
import type { MessageArgsProps } from 'antd';
import { createStyles } from 'antd-style';

export interface MessageConfig extends MessageArgsProps {
  /**
   * @description 自定义样式类名
   */
  customClassName?: string;
}

const useStyles = createStyles(({ token, css }) => ({
  message: css`
    .ant-message-notice-content {
      border-radius: ${token.borderRadius}px;
      box-shadow: ${token.boxShadow};
    }
  `,
}));

// 创建自定义的 message 对象，保留所有原始 API
const Message = {
  ...antdMessage,
  success: (config: MessageConfig | string) => {
    const className = typeof config === 'object' ? config.customClassName || config.className : undefined;
    return antdMessage.success(typeof config === 'string' ? config : { ...config, className });
  },
  error: (config: MessageConfig | string) => {
    const className = typeof config === 'object' ? config.customClassName || config.className : undefined;
    return antdMessage.error(typeof config === 'string' ? config : { ...config, className });
  },
  info: (config: MessageConfig | string) => {
    const className = typeof config === 'object' ? config.customClassName || config.className : undefined;
    return antdMessage.info(typeof config === 'string' ? config : { ...config, className });
  },
  warning: (config: MessageConfig | string) => {
    const className = typeof config === 'object' ? config.customClassName || config.className : undefined;
    return antdMessage.warning(typeof config === 'string' ? config : { ...config, className });
  },
  loading: (config: MessageConfig | string) => {
    const className = typeof config === 'object' ? config.customClassName || config.className : undefined;
    return antdMessage.loading(typeof config === 'string' ? config : { ...config, className });
  },
  open: (config: MessageConfig) => {
    const className = config.customClassName || config.className;
    return antdMessage.open({ ...config, className });
  },
};

export default Message;

